package com.res.common.controller;

import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttributes;

import com.res.simulator.handler.ScanPageHandler;
import com.res.simulator.model.GenericAPIExecutionModel;
import com.res.simulator.model.WADLScanModel;
import com.res.simulator.view.WADLDataView;
import com.res.system.referencedata.ReferenceDataManager;

@Controller
@SessionAttributes
public class ScanningPageController extends BaseController {

	@RequestMapping("/ScanningPage")
	public String home(@ModelAttribute("WADLScanModel") final WADLScanModel model) {

		return "scanninglayout";
	}

	@RequestMapping(value = "/scanapplication_wadl", params = { "systemName", "releaseName", "url" , "Scan"})
	public String scan(@ModelAttribute("WADLScanModel") final WADLScanModel model, final BindingResult result) throws Exception {

		System.out.println("System Name : " + model.getSystemName());
		System.out.println("Release : " + model.getReleaseName());
		System.out.println("Url : " + model.getUrl());

		final ScanPageHandler handler = new ScanPageHandler();

		final WADLDataView view = handler.process(model);
		
		//clear method
		ReferenceDataManager.cleanReferenceData();
		
		getSession().removeAttribute("systemCollection");
		getSession().removeAttribute("packageNameCollection");

		return "redirect:ScanningPage.htm";
	}

}